const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  const Comment = sequelize.define("Comment", {
    // 评论内容，不能为空
    content: {
      type: DataTypes.TEXT,
      allowNull: false,
    },
    // 用户ID，对应 User 表的主键
    userId: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    // 文章ID，对应 Post 表的主键
    postId: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
  });

  Comment.associate = (models) => {
    Comment.belongsTo(models.User, { foreignKey: "userId" });
    Comment.belongsTo(models.Post, { foreignKey: "postId" });
  };

  return Comment;
};
